#!/usr/bin/env python
# -*- coding:utf8 -*-

"""
@version: 
@author: lh
@license: Apache Licence 
@contact: liuhuan0672@gmail.com
@site: 
@software: PyCharm
@file: 0000.py
@time: 2016/1/19 17:22


第 0000 题：将你的 QQ 头像（或者微博头像）右上角加上红色的数字，类似于微信未读信息数量那种提示效果


tips: / 表示浮点数除法，如果左右两边有浮点数，结果一定为浮点数数
      // 表示整数除法，取结果的最小整数
"""
from PIL import Image, ImageDraw, ImageFont


def add_num_to_img(file_path):
    im = Image.open(file_path)
    im_draw = ImageDraw.Draw(im)
    font = ImageFont.truetype("arial.ttf", int(im.size[0] // 5))
    im_draw.text((int(im.size[0] - im.size[0] / 10), 5), "4", (256, 0, 0), font=font)
    del im_draw
    im.save('./result/result.jpg')


if __name__ == '__main__':
    add_num_to_img("./static/demo.jpg")
    # if len(sys.argv) <= 1:
    #     print("Need at least one parameter.Try to execute 'python 0000.py $image_path'")
    # else:
    #     for infile in sys.argv[1:]:
    #         try:
    #             add_num_to_img(infile)
    #             print('Success!')
    #         except IOError:
    #             print("Can't open image!")
    #             pass
